﻿using System.Collections.Generic;

namespace Blackbird.Common
{
    public class SparseGraph<T> : Graph<T>
    {
        private Dictionary<ulong, T> _storageDictionary;

        public SparseGraph(params int[] dimensionExtents)
            : base(dimensionExtents)
        {
        }

        protected internal override T GetItemByIndex(ulong index)
        {
            if (!_storageDictionary.ContainsKey(index))
                return default(T);

            return _storageDictionary[index];
        }

        protected internal override void SetItemByIndex(T item, ulong index)
        {
            _storageDictionary[index] = item;
        }

        public override void InitializeStorage() {
            _storageDictionary = new Dictionary<ulong, T>();
        }
    }
}